﻿using System;
using Sirenix.OdinInspector;
using UnityEngine;

namespace HotPlayer.Physic2D
{
    public class HotPolygonCollider2D : MonoBehaviour
    {
        public Polygon2D shape;

        public Vector2[] points;

        [Button]
        public void RefreshShape()
        {
            shape ??= new Polygon2D();
            shape.Update(points, transform.localToWorldMatrix);
        }
        
        private void OnDrawGizmos()
        {
            if (points != null && points.Length > 2)
            {
                RefreshShape();

                var convertXZ = HotPhysic2DUtils.ConvertToVec3XZ(shape.pointsWS);
                // var span = new ReadOnlySpan<Vector3>(HotPhysic2DUtils.Translate(convertXZ, transform.position));
                var span = new ReadOnlySpan<Vector3>(convertXZ);
                Gizmos.DrawLineStrip(span, true);
            }
        }
    }
}